Repository navigation
Search inside thread messages from the Cmd K palette - #445
Merged
abhishekgahlot2 merged 1 commit intoNov 13, 2026
Merged
abhishekgahlot2 merged 1 commit into
abhishekgahlot2 merged 1 commit into
Conversation
Cmd K only matched thread titles, so a thread could be found only by its first line. It now also finds the words said inside a thread and opens the thread at the turn that said them. GET /api/runs/search?q= (backend/src/runs/message-search.ts) searches the two texts a thread shows as messages, the prompts people typed and the agent's replies (runs.prompt and runs.summary), with Postgres full-text search on the simple configuration: - Every query word has to be in the same message, matched from the start of a word, so "deplo stag" finds "Deploy to staging". The query goes through the same parser as the messages and each word is quoted as a prefix term, so nothing typed is read as tsquery syntax. - An ILIKE check on each word runs first. Every full-text match passes it, so only candidate rows pay for to_tsvector. On 50,000 runs with long replies in one workspace, a selective query took about 170 ms and one that matched every reply about 1.3 s; without the check every query took about 3.1 s. - It reads only what the thread list shows: the member's workspace, user-created runs under a user-created root, and no gateway child sessions. It answers the newest matching message of each thread, newest thread first, with a ts_headline snippet around the match. - The query runs under a 5 second statement_timeout and answers 503 when it is cut off. q is required and at most 200 characters; limit is 1 to 25. The palette (frontend/components/shell/) asks after a 200 ms pause in typing, aborts the request a newer query replaces, and lists the matches in a Messages group under the title matches. A thread already listed by title is not repeated for its first prompt. While the answer is pending the empty line stays hidden, and a failed search says so instead of reading as "nothing found". The palette now turns cmdk's own filtering off, since every list in it is already filtered and ordered, and the list gets min-w-0 so a long row no longer widens it past the dialog. Picking a match opens /session/:thread?message=:run. The session page passes the run id down and Conversation jumps to that turn, stops following the bottom, and holds the turn in place while a long thread's window fills in around it, until the reader scrolls, clicks or types. The jump moved into jumpToRunTurn, which the message rail now shares. Docs: the route on the Runs API page, the message link on the Session view page, and the command palette card.
Contributor
|
Merged, thanks @officialasishkumar. Finding a thread by something said inside it is a big step up for Cmd K, and the bound search term, workspace scoping and 5 s statement limit keep it safe. The GIN index you offered as a follow-up would be welcome. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By opening this pull request you agree to the Contributor License Agreement. On your first pull request a bot asks you to sign it with a one-line comment.
Fixes #91
⌘K only matched thread titles, so a thread you remembered by something the agent said could not be found. It now also searches what was said inside threads, lists the matches under the title matches with a snippet, and opens the thread at the turn that said it.
What changed
GET /api/runs/search(backend/src/runs/message-search.ts, route inread-routes.ts)role: "user",runs.prompt) and the agent's replies (role: "agent",runs.summary).simpleconfiguration, so no language's stemming or stop words apply. Every query word has to be in the same message and matches from the start of a word:deplo stagfinds "Deploy to staging",hookdoes not find "webhook".to_tsvector('simple', q)), and each word is quoted as a prefix term ('word':*). Quotes, backslashes,&,|,!and:*typed into the box are plain words, never tsquery syntax.to_tsvector, anILIKEcheck on each word (wildcards escaped) skips rows that cannot match. Every full-text match passes it, so it changes cost, not results. On 50,000 runs with long replies in one workspace: about 170 ms for a selective query, 350 ms for one matching every prompt, and 1.3 s for one matching every reply. Without the check every query took about 3.1 s.origin is nullruns under anorigin is nullthread root (no automation or internal threads), and no gateway child sessions (they fold under their parent turn instead of showing as a message; samechild-session:idempotency checkrepo.tsuses).snippetis ats_headlinefragment around the match, in fragment mode so the words before the first match come along;thread_promptis the root prompt the title comes from.qis required and at most 200 characters (400).limitis 1 to 25, default 10.statement_timeout, and a cut-off search answers503(read by SQLSTATE 57014 throughsqlStateOf).I did not add an index. A GIN index on
runswould need either a blockingCREATE INDEXin a migration or the online-index path thatsrc/db/online-indexes/uses forcanonical_events, and with theILIKEcheck and the per-workspaceidx_runs_orgscan the timings above seemed fine for a first version. Happy to add one in a follow-up if you'd like.The palette (
frontend/components/shell/)message-search.ts: the fetch throughbackendFetch, a decoder, anduseMessageSearch. It asks after a 200 ms pause, only from 2 characters, and aborts the request a newer query replaces, so an older answer never shows over a newer query.search-command.tsxrenders a Messages group right under Threads: the snippet,in <thread title>, andYou/Agentwith the time. A thread already listed by title is not repeated for its first prompt.Command.Loading) and the empty line stays hidden. A failed search says "Couldn't search messages. Change the search to try again." instead of reading as nothing found. The empty line now reads "No commands, threads or messages found".shouldFilter={false}to cmdk (new optional prop onCommandMenu.Dialog). Every list in it is already filtered bymatchesEveryWordand ordered byrankThreads, and cmdk's scoring would hide message rows whose words are not in the row's value and reorder the rest. Empty groups are skipped explicitly, since cmdk no longer hides them.CommandMenu.Listgetsmin-w-0. Without it a long row (a snippet, or a long thread title) widened the list's grid column past the 600 px dialog and clipped every row's right-hand meta. I measured 833 px inside the 598 px dialog before, 598 px after.Opening at the message (
frontend/app/session/(thread)/[id]/page.tsx,components/chat/,components/session-ui/message-scroller-rail.tsx)/session/:thread_id?message=:run_id. The page readsmessagefromsearchParamsand passes it toSessionView, then on toConversationasfocusRunId.Conversationjumps to that turn after its first follow-to-bottom, and stops following the bottom so streaming output does not scroll it away.jumpToRunTurn(find the turn bydata-run-id, thenjumpToTurn) is now shared with the message rail.holdRunTurnkeeps the turn in place while the thread settles. In a long thread the turn window opens it as a sized placeholder, fetches it as it comes into view, and keeps another row still while heights change. I saw the turn drift by up to 2,357 px, or get swapped back to a placeholder, without this. Whenever any turn resizes it jumps back, until the reader scrolls, clicks or types anywhere on the page.session-view.tsxis at its 990-line ratchet baseline, so the prop rides existing lines there.Docs: the route and a paragraph on the Runs API page, the
?message=link on the Session view page, and the command palette card in Product experience.Across a release: new route, new optional prop, and an optional query parameter. An old backend answers
/api/runs/searchthrough/:idwith404 run not found, so the new palette shows its failure line and title search still works.Tests
backend/test/message-search.test.ts, through the real route and database:limit=3, a limit over 25 held at 25, a non-number giving 10(,&,|,!,:*, a path with_, and100%read as plain words; punctuation alone finds nothingqanswers 400Frontend:
message-search.test.ts: the decoder, the request path and encoding, a 503 or an odd body thrown rather than read as no matches, the query rules, dropping a listed thread's title prompt, the hrefmessage-search.interaction.test.tsxmounts the hook in happy-dom over a stubbed fetcher: one request after a burst of keystrokes, none under 2 characters, the in-flight request aborted and its late answer ignored,failedon a 503,idleagain when clearedmessage-scroller-rail.dom.test.ts:jumpToRunTurnon real nodes, andholdRunTurnwith a fakeResizeObserver. It jumps back after the turn moves down or up, lets go on wheel, touch, pointer or key anywhere, and on cleanupChecks with Bun 1.3.14, backend tests on
pgvector/pgvector:0.8.6-pg16-bookworm:bun run typecheck(root): passescd backend && bun run test: 3633 pass, 0 fail, then the Slack suite 119 pass, 0 failcd frontend && bun run test: 2001 pass, 0 failcd frontend && bun run lint: 248 warnings and 22 infos, the same asmaincd frontend && bun run build: passescd docs-site && bunx blume validate: no broken linksbun test scripts/agent-docs.test.ts: 5 passEnd to end
I ran a real backend on its own Postgres and a production build of the frontend (
next start), signed up a member, and drove it with Playwright at 1440x900. The workspace had three threads: an 80-turn thread (long enough to load windowed) whose turn 5 reply mentions "the payment webhook", a short thread whose second reply mentions "our webhook endpoint", and a thread titled "Retry failed webhook deliveries".webhook: Threads lists "Retry failed webhook deliveries". Messages lists "Stripe calls our webhook endpoint at /hooks/payments; failures land in the dead-letter queue", in Set up the staging deploy, Agent · 1h, and "The checkout test raced the payment webhook. I made it wait for the webhook before it asserts the order total", in Plan the checkout rewrite, Agent · 3d. The titled thread is not repeated under Messages. The footer reads 3 results, and every row's meta is visible./session/e2e-long-1?message=e2e-long-5. Turn 5 was an unloaded placeholder in that long thread. It was fetched as it came into view, and its top settled 8 px under the scroller's top (the rail's inset) with the reply visible. Same result on three runs.?message=the thread still opens at its newest turn.dead-letter, a word said only inside a thread, shows just the Messages group, and Enter opens/session/e2e-short-1?message=e2e-short-2.zzqx nothingshows "No commands, threads or messages found" once the search has answered.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.